namespace DotNetNuke.Entities.Host
{
    using DotNetNuke.Common.Utilities;
    using DotNetNuke.Data;
    using System;
    using System.Data;

    public class HostSettingsController
    {
        public IDataReader GetHostSetting(string SettingName)
        {
            return DataProvider.Instance().GetHostSetting(SettingName);
        }

        public IDataReader GetHostSettings()
        {
            return DataProvider.Instance().GetHostSettings();
        }

        public void UpdateHostSetting(string SettingName, string SettingValue)
        {
            this.UpdateHostSetting(SettingName, SettingValue, false);
        }

        public void UpdateHostSetting(string SettingName, string SettingValue, bool SettingIsSecure)
        {
            IDataReader dr = DataProvider.Instance().GetHostSetting(SettingName);
            if (dr.Read())
            {
                DataProvider.Instance().UpdateHostSetting(SettingName, SettingValue, SettingIsSecure);
            }
            else
            {
                DataProvider.Instance().AddHostSetting(SettingName, SettingValue, SettingIsSecure);
            }
            dr.Close();
            DataCache.ClearHostCache(false);
        }
    }
}

